package com.wocao.utils;

import com.wocao.entity.SysMenu;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class TreeUtilsByUsername {
    public static List<SysMenu> menusToTree(List<SysMenu> treeList) {
        //操作所有组织机构数据
        Map<Long, List<SysMenu>> groupMap = treeList.stream().collect(Collectors.groupingBy(SysMenu::getParentId));
        treeList.forEach(sysMenu-> {
            sysMenu.setChildSysMenusByUsername(groupMap.get(sysMenu.getMenuId()));
        });
        return treeList.stream().filter(sysMenu -> sysMenu.getParentId().equals(0L)).collect(Collectors.toList());

    }
}
